package com.dangf.hzapp;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Application;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.widget.Toast;

import com.dangf.hzapp.activity.LoginActivity;
import com.dangf.hzapp.activity.MainActivity;
import com.dangf.hzapp.entity.User;
import com.tencent.android.tpush.XGPushConfig;
import com.tencent.android.tpush.XGPushManager;

/**
 * 全局
 * @author 韦海生
 * @date 2014年8月1日
 */
public class HzApplication extends Application {

	@Override
	public void onCreate() {
		super.onCreate();
		XGPushManager.registerPush(getApplicationContext(),XGPushConfig.getToken(getApplicationContext()));
	}
	
	
	
	/**
	 * 退出登录
	 */
	public void outUser(final Activity ac){
		new AlertDialog.Builder(ac).setTitle("确定退出登录？")
		.setPositiveButton("确定", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				Config.cacheUser(ac, new User());
				Toast.makeText(ac, "登录已注销！", Toast.LENGTH_SHORT).show();
				Intent intent = new Intent(ac, LoginActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
				startActivity(intent);
				MainActivity.mainActivity.finish();
			}
		})
		.setNegativeButton("返回", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {}
		}).show();
	}
	
	/**
	 * 退出软件
	 */
	public void outApp(Activity ac){
		new AlertDialog.Builder(ac).setTitle("确定退出软件？")
		.setPositiveButton("确定", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				int nPid = android.os.Process.myPid();  
                android.os.Process.killProcess(nPid);  
			}
		})
		.setNegativeButton("返回", new OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {}
		}).show();
	}
	
	
}
